package business.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.Favorite;
import business.FavoriteService;
import dao.FavoriteDAO;

public class FavoriteServiceImpl implements FavoriteService {

	private FavoriteDAO favoriteDao;

	public long getTotalCount() {
		return favoriteDao.findTotalCount();
	}

	public List<Favorite> getAllFavorites() {
		return favoriteDao.findAll();
	}

	public List<Favorite> getFavoritesByUserId(long userId) {
		return favoriteDao.findByUserId(userId);
	}

	public Favorite getByUserIdItemId(long userId, String itemId) {
		return favoriteDao.findByUserIdItemId(userId, itemId);
	}

	public List<Favorite> getFavoritesByUserId(int start, int pageSize, long userId) {
		return favoriteDao.findByUserId(start, pageSize, userId);
	}

	@Required
	public void setFavoriteDao(FavoriteDAO favoriteDao) {
		this.favoriteDao = favoriteDao;
	}

	@Transactional
	public void addFavorite(String name) {
		Favorite e = new Favorite();
		favoriteDao.create(e);
	}

	@Transactional
	public void addFavorite(Favorite favorite) {
		favoriteDao.create(favorite);
	}

}